#!/usr/bin/env node

const rd = require('rd');

const fs = require("fs");

// 同步列出目录下的所有文件
let files = rd.readSync('F:\\dev\\gaiay\\all');
for (let f of files) {

    let stat = fs.statSync(f);


    if (f.indexOf("resources") > 0 && stat.isFile()) {
        // console.log(f.substr(f.indexOf("resources")).split("\\") == 1)
        if (f.substr(f.indexOf("resources")).split("\\").length === 2) {
            copyToEnv(f, "dev");
            copyToEnv(f, "prod");
            copyToEnv(f, "test");

        }
    }
}

function copyToEnv(f, env) {
    let dist = f.replace("resources", "resources\\" + env);
    let path = dist.substr(0, f.lastIndexOf("\\")) + "\\" + env;
    if (!fs.existsSync(path)) {
        fs.mkdirSync(path);
    }
    fs.copyFileSync(f, dist);
    console.log(f);
    console.log(dist);
}